<?php
/**
 * Index page. Simply lists all wiki files.
 * 
 *     SCMwiki Copyright (C) 2010  Callan Bryant <callan1990@googlemail.com>
 *     
 *     Based on Voswork - A simple, fast PHP filesystem abstraction layer
 *     Voswork Copyright (C) 2010  Callan Bryant <callan1990@googlemail.com>
 * 
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * 
 * @package main
 * @author Callan Bryant <callan1990@googlemail.com>
 */

$search = strip_tags($_REQUEST['keywords']);

$indexer = scmwikiCrawler::getIndexer();
$dict = new didYouMean();

$results = $indexer->search($search);

if ($results)
{
	// this was a successful search -- add the search to teh dictionary
	$dict->add($search);
	$page = new indexPage($results);
}
// no results. Let's see if there is a suggestion from the dictionary
// of successful searches
elseif ($guess = $dict->guess($search))
{
	$results = $indexer->search($guess);
	$page = new indexPage($results);
	$page->description = "No results for '$search' -- showing results for <strong>$guess</strong>";

	// pages returned by that search may have vanished, returning nothing.
	// Remove the phrase
	if (!$results)
		$dict->remove($search);
}
else
{
	$page = new template();
	$page->article = 'No results found for your search query';
	$page->note = 'Try adding more tags to each page';
}

$page->title = "Search results for '$search'";
echo $page;
?>
